package com.robot.agent.mq;

import com.alibaba.fastjson.JSON;
import com.robot.agent.dao.AgentDao;
import com.robot.agent.pojo.Agent;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "agent")
public class AgentListener {
    @Autowired
    private AgentDao agentDao;

    @RabbitHandler
    public void exec(String str){
        if(str.startsWith("agent")){
            Agent agent= JSON.parseObject(str.replace("agent",""),Agent.class);
            agent.setBankAccount(agent.getBankAccount().replace(" ",""));
            System.out.println(agent.toString());
            agentDao.save(agent);
        }
    }
}
